package com.homegoods.videomodule.app;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.multidex.MultiDex;
import android.support.v4.app.FragmentManager;

import com.cyt.chattlibrary.LiveKit;
import com.cyt.chattlibrary.face.SmileyParser;
import com.cyt.video.customerMediaPlayer.JZKSYPlayer;
import com.homegoods.integration.AppLifecycles;
import com.homegoods.integration.ConfigModule;
import com.kedll.library.receiver.ActivitiesManager;

import java.util.List;

import cn.jzvd.Jzvd;

/**
 * @author QiQi
 * @ClassName: GlobalConfiguration
 * @date 2018/9/22
 * @description
 */
public class GlobalConfiguration implements ConfigModule {
    @Override
    public void applyOptions(Context context) {

    }

    @Override
    public void injectAppLifecycle(Context context, List<AppLifecycles> lifecycles) {
        lifecycles.add(new AppLifecycles() {
            @Override
            public void attachBaseContext(@NonNull Context base) {
                MultiDex.install(base);
            }

            @Override
            public void onCreate(@NonNull Application application) {
                SmileyParser.init(application);
                Jzvd.setMediaInterface(new JZKSYPlayer(application));
                LiveKit.init(application, "");
            }

            @Override
            public void onTerminate(@NonNull Application application) {

            }
        });
    }

    @Override
    public void injectActivityLifecycle(Context context, List<Application.ActivityLifecycleCallbacks> lifecycles) {

        lifecycles.add(new Application.ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                ActivitiesManager.getInstance().addActivity(activity);
            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {

            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {
                if (activity.isFinishing()) {
                    ActivitiesManager.getInstance().removeActivity(activity);
                }
            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {

            }
        });

    }

    @Override
    public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {

    }
}
